package com.example.springboot_vue.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.springboot_vue.common.PageDto;
import com.example.springboot_vue.entity.Goodstype;
import com.example.springboot_vue.mapper.GoodstypeMapper;
import com.example.springboot_vue.service.GoodstypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author sgp
 * @since 2024-07-19
 */
@Service
public class GoodstypeServiceImpl extends ServiceImpl<GoodstypeMapper, Goodstype> implements GoodstypeService {

    @Autowired
    private GoodstypeMapper goodstypeMapper;
    @Override
    public PageDto<Goodstype> selectAll(Goodstype goodstype) {
        QueryWrapper<Goodstype> queryWrapper = new QueryWrapper<>();
        if(ObjectUtils.isNotEmpty(goodstype.getName())){
            queryWrapper.lambda().like(Goodstype::getName,goodstype.getName());
        }
        Page<Goodstype> page = new Page<>(goodstype.getPage(), goodstype.getSize());
        Page<Goodstype> selectPage = goodstypeMapper.selectPage(page, queryWrapper);
        PageDto<Goodstype> pageDto = new PageDto<>();
        pageDto.setTotal(selectPage.getTotal());
        pageDto.setList(selectPage.getRecords());
        return pageDto;
    }
}
